<!--
  -    Copyright (c) 2018-2025, lengleng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: lengleng (wangiegie@gmail.com)
  -->
<template>
  <div class="execution">
    <basic-container>
      <avue-crud ref="crud"
                 :page.sync="page"
                 :data="tableData"
                 :permission="permissionList"
                 :table-loading="tableLoading"
                 :option="tableOption"
                 @on-load="getList"
                 @search-change="searchChange"
                 @refresh-change="refreshChange"
                 @size-change="sizeChange"
                 @current-change="currentChange"
                 @row-update="handleUpdate"
                 @row-save="handleSave"
                 @row-del="rowDel">
        <template slot-scope="{row,index}" slot="menu">
          <!--                          <button type="button" class="el-button el-button&#45;&#45;text el-button&#45;&#45;small" @click="approve(row,index)"><i-->
          <!--                            class="el-icon-d-caret"></i><span>-->
          <!--                         开始审批-->
          <!--                        </span></button>-->
          <button type="button" class="el-button el-button--text el-button--small" @click="tg(row,index)"><i
            class="el-icon-d-caret"></i><span>
                                         通过
                                        </span></button>
          <button type="button" class="el-button el-button--text el-button--small" @click="bh(row,index)"><i
            class="el-icon-d-caret"></i><span>
                                         驳回
                                        </span></button>
          <button type="button" class="el-button el-button--text el-button--small" @click="ck(row,index)"><i
            class="el-icon-d-caret"></i><span>
                                         查看图片
                                        </span></button>
        </template>
      </avue-crud>

      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="50%">
        <span>订单图片</span>
        <div class="block" v-for="(item,index) in imgarr">
          <span class="demonstration"></span>
          <el-image :src="item"></el-image>
        </div>
        <span>好评图片</span>
        <div class="block" v-for="(item,index) in imgarr2">
          <span class="demonstration"></span>
          <el-image :src="item"></el-image>
        </div>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import {addObj, bhObj, delObj, fetchList, putObj, tgObj} from '@/api/xlmorderverify'
import {getObj as getuser} from '@/api/xlmuser'
import {getObj as getshop} from '@/api/xlmshop'
import {getObj as getorder} from '@/api/xlmorder'

import {tableOption} from '@/const/crud/xlmorderverify'
import {mapGetters} from 'vuex'

export default {
  name: 'xlmorderverify',
  data() {
    return {
      imgarr: [],
      imgarr2:[],
      dialogVisible: false,
      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption
    }
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList() {
      return {
        addBtn: false,
        delBtn: this.vaildData(this.permissions.demo_xlmorderverify_del, false),
        editBtn: this.vaildData(this.permissions.demo_xlmorderverify_edit, false)
      };
    }
  },
  methods: {
    ck: function (row, index) {
      this.imgarr = row.orderimg.substring(1, row.orderimg.length - 1)
        .split(
          ",")
      this.imgarr2= row.goodimg.substring(1, row.goodimg.length - 1).split(
        ",")
      this.dialogVisible = true

    },
    tg: function (row, index) {
      let _this = this
      this.$confirm('是否通过此单', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async function () {
        await getshop(row.shopid).then(async (res) => {
          let title = res.data.data.title
          await getorder(row.orderid).then(async (res) => {
            let userid = res.data.data.payid
            await getuser(userid).then(async (res) => {
              let alipay = res.data.data.alipay
              await _this.$confirm("此单店名：" + title + " 收款方式：" + alipay, '提示，请给此人转账', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(function () {
                return tgObj(row.id)
              })
            })
          })
        }).catch((err) => {
          return
        })

      }).then(data => {
        this.$message.success('操作完成')
        this.getList(this.page)
      }).catch(() => {
        this.$message.error('通过失败')
      })
    },
    bh: function (row, index) {
      this.$confirm('是否驳回此单', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return bhObj(row.id)
      }).then(data => {
        this.$message.success('驳回成功')
        this.getList(this.page)
      }).catch(() => {
        this.$message.error('驳回失败')
      })
    },
    getList(page, params) {
      this.tableLoading = true
      fetchList(Object.assign({
        current: page.currentPage,
        size: page.pageSize
      }, params, this.searchForm)).then(response => {
        this.tableData = response.data.data.records
        this.page.total = response.data.data.total
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    rowDel: function (row, index) {
      this.$confirm('是否确认删除ID为' + row.id, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delObj(row.id)
      }).then(data => {
        this.$message.success('删除成功')
        this.getList(this.page)
      })
    },
    handleUpdate: function (row, index, done, loading) {
      putObj(row).then(data => {
        this.$message.success('修改成功')
        done()
        this.getList(this.page)
      }).catch(() => {
        loading();
      });
    },
    handleSave: function (row, done, loading) {
      addObj(row).then(data => {
        this.$message.success('添加成功')
        done()
        this.getList(this.page)
      }).catch(() => {
        loading();
      });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize
    },
    currentChange(current) {
      this.page.currentPage = current
    },
    searchChange(form, done) {
      this.searchForm = form
      this.page.currentPage = 1
      this.getList(this.page, form)
      done()
    },
    refreshChange() {
      this.getList(this.page)
    }
  }
}
</script>
